{{include 'header'}}
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="navbar-title">
        <div class="container">
            <div class="row">
                <span id="goBack" class="glyphicon glyphicon-chevron-left pull-left"></span>
                个人资料
                <span id="register" class="glyphicon glyphicon-user pull-right invisible"></span>
            </div>
        </div>
    </div>
</nav>
<div class="container">
    <form action="/user/photo" method="POST" enctype="multipart/form-data">
        <div class="form-group">
            <input type="file" name="photo" required accept=".jpg,.png">
        </div>
        <input type="submit" class="btn btn-success form-control" value="上传头像"></input>
    </form>
</div>
<div class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span>&times;</span></button>
                    <h4 class="modal-title">智游教育</h4>
                </div>
                <div class="modal-body"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">确定</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="js/jquery.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
    $('form').submit(function(ev){
        ev.preventDefault()
        var data = new FormData(this)
        $.post({
            url:'/user/photo',
            data:data,
            contentType:false,  //默认的格式是 application/x-www-form-urlencoded
            processData:false, // 默认发送到服务器的数据，会发生数据转换，防止自动转换数据格式
            success:function(res){
                $('.modal-body').text(res.message)
                $('.modal').modal('show').on('hidden.bs.modal', function(){
                    if(res.code == 'success'){
                        location.href = '/'
                    }

                })
            }
//            '/user/photo', data, function(res){
//                $('.modal-body').text(res.message)
//                $('.modal').modal('show').on('hidden.bs.modal', function(){
//                    if(res.code == 'success'){
//                        location.href = '/'
//                    }
//
//                })
//            }
        })
    })
</script>
</html>